//  求平均值接口与实现该接口的类。
package org.langqiao.network.judge;
public interface Average                                   //求平均值接口
{
    public abstract double average(double table[]);        //求数组元素的平均值
}

class AverageAll implements Average                        //求所有元素的平均值      
{
    public double average(double table[])
    {
        if (table!=null && table.length>0) 
        {
            double sum=0.0;
            for (int i=0; i<table.length; i++)
                sum += table[i];  
            return sum/table.length;
        }
        return 0.0;
    }
}

class AverageExceptMaxMin implements Average              //去掉最高分和最低分，再求平均
{
    public double average(double table[])
    {
        if (table!=null && table.length>2)
        {
            double sum=table[0], max=table[0], min=table[0];
            for (int i=1; i<table.length; i++)
            {
                sum += table[i];  
                if (table[i]>max)
                    max = table[i];
                if (table[i]<min)
                    min = table[i];
            }
            return (sum-max-min)/(table.length-2);
        }
        return 0.0;
    }
}
